/* 
 * File:   SBSLog.cpp
 * Author: lgr013
 * 
 * Created on 23 de octubre de 2014, 16:57
 */


#include "SBSLog.h"

SBSLog::SBSLog(int lm) {
    if (!this->myLog.is_open()){
        this->myLog.open("Doc/Error.log",ios_base::app);
        this->myLogMode=lm;
        }
}

SBSLog::~SBSLog() {
//    cout<<"Destructor de SBSLog"<<endl;
    this->writeInLog(2,"\n");
    this->myLog.close();
}

int SBSLog::getMyLogMode(){
    int mlm;
    mlm = this->myLogMode;
    return mlm;
}

char* SBSLog::getMyTimeStamp(){
    char* mts;
    mts = this->myTimeStamp;
    return mts;
}

void SBSLog::setMyTimeStamp(){
    this->myLog<<endl;
    time_t now = time(0);
    this->myTimeStamp = ctime(&now);
    this->myLog<< this->getMyTimeStamp();
    this->myLog<<endl;
}


bool SBSLog::writeInLog(char logmode, string linetowrite){
    SBSLog* myLogFile;
    bool success = true;
    switch (MY_LOG_MODE){
        case 0: myLogFile->getInstance(MY_LOG_MODE).myLog<< linetowrite;
                break;
        case 1: if (logmode != 0){
                myLogFile->getInstance(MY_LOG_MODE).myLog << linetowrite;
                }
                break;
        case 2: if (logmode == 2){
                myLogFile->getInstance(MY_LOG_MODE).myLog << linetowrite;
                }
                break;
    }
    return success;
}

    SBSLog& SBSLog::getInstance(int ml){
    static SBSLog myLogFile(ml);
    return myLogFile;
}

